/**
 * Title :	jFamilyTree generator
 * Description: jFamilyTree generator
 * Version:	provider
 * Copyright (c) 2001-2008
 * Terms of use:see license agreement at http://treebolic.sourceforge.net/en/license.htm
 * Author: Bernard Bou
 * Company: bsys
 */
package jFamilyTree.site;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Observable;
import java.util.Observer;
import java.util.Properties;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.Icon;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JDialog;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JProgressBar;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;

import org.w3c.dom.Document;

import jFamilyTree.Messages;
import jFamilyTree.commons.FileDialogs;
import jFamilyTree.commons.Persist;
import jFamilyTree.commons.Utils;
import jFamilyTree.dialogs.main.XSiteDialog;
import jFamilyTree.generator.Pair;
import jFamilyTree.provider.xml.dom.Parser;

/**
 * Make site dialog
 * 
 * @author Bernard Bou
 */
public class MakeSiteDialog extends JDialog
{
	private static final long serialVersionUID = 1L;

	/**
	 * DOM document (source)
	 */
	private Document theDocument;

	// C O M P O N E N T S

	/**
	 * Site information
	 */
	private JLabel theSiteLabel;

	/**
	 * Template repository information
	 */
	private JLabel theRepositoryLabel;

	/**
	 * Image repository information
	 */
	private JLabel theImageRepositoryLabel;

	/**
	 * Title input
	 */
	private JTextField theTitleTextField;

	/**
	 * XML file input
	 */
	private JTextField theXMLFileTextField;

	/**
	 * HTML file input
	 */
	private JTextField theHTMLFileTextField;

	/**
	 * Progress label
	 */
	private JLabel theProgressLabel;

	/**
	 * Progress bar
	 */
	private JProgressBar theProgressBar;

	/**
	 * Wheter to chain with run site
	 */
	private JCheckBox theRunCheckBox;

	/**
	 * Properties (input/output)
	 */
	private Properties theProperties;

	// C O N S T R U C T OR

	/**
	 * Constructor
	 */
	public MakeSiteDialog(Properties theseProperties)
	{
		super();
		theProperties = theseProperties;
		initialize();
	}

	/**
	 * Initialize
	 */
	private void initialize()
	{
		setTitle(Messages.getString("MakeSiteDialog.0")); //$NON-NLS-1$
		setResizable(true);

		// checkbox
		theRunCheckBox = new JCheckBox(Messages.getString("MakeSiteDialog.8")); //$NON-NLS-1$

		// buttons
		JButton thisTransferButton = new JButton();
		thisTransferButton.setText(Messages.getString("MakeSiteDialog.2")); //$NON-NLS-1$
		JButton thisDestinationButton = new JButton();
		thisDestinationButton.setText(Messages.getString("MakeSiteDialog.3")); //$NON-NLS-1$
		JButton thisCancelButton = new JButton();
		thisCancelButton.setText(Messages.getString("MakeSiteDialog.4")); //$NON-NLS-1$
		JButton thisBrowseRepositoryButton = new JButton();
		thisBrowseRepositoryButton.setText(Messages.getString("MakeSiteDialog.5")); //$NON-NLS-1$
		JButton thisBrowseImageRepositoryButton = new JButton();
		thisBrowseImageRepositoryButton.setText(Messages.getString("MakeSiteDialog.5")); //$NON-NLS-1$
		JButton thisModeButton = new JButton();
		thisModeButton.setText(Messages.getString("MakeSiteDialog.5")); //$NON-NLS-1$

		// images
		Icon thisIcon = new ImageIcon(MakeSiteDialog.class.getResource("images/sitemake.png")); //$NON-NLS-1$
		JLabel thisImageLabel = new JLabel();
		thisImageLabel.setBackground(Color.RED);
		thisImageLabel.setIcon(thisIcon);
		thisImageLabel.setVerticalTextPosition(JLabel.TOP);
		thisImageLabel.setHorizontalTextPosition(JLabel.CENTER);
		thisImageLabel.setAlignmentX(Component.CENTER_ALIGNMENT);
		thisImageLabel.setText(Messages.getString("MakeSiteDialog.1")); //$NON-NLS-1$

		// progress
		theProgressBar = new JProgressBar();
		theProgressLabel = new JLabel(Messages.getString("MakeSiteDialog.6")); //$NON-NLS-1$

		// labels
		theRepositoryLabel = new JLabel();
		theRepositoryLabel.setEnabled(false);
		theImageRepositoryLabel = new JLabel();
		theImageRepositoryLabel.setEnabled(false);
		theSiteLabel = new JLabel();
		theSiteLabel.setEnabled(false);

		// textfields
		theTitleTextField = new JTextField(16);
		theXMLFileTextField = new JTextField(16);
		theHTMLFileTextField = new JTextField(16);

		// assemble
		JPanel thisDataPanel = new JPanel();
		thisDataPanel.setLayout(new GridBagLayout());
		thisDataPanel.add(new JLabel(Messages.getString("MakeSiteDialog.11")), new GridBagConstraints(0, 0, 1, 1, 0., 0., GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 20, 0, 10), 0, 0)); //$NON-NLS-1$
		thisDataPanel.add(new JLabel(Messages.getString("MakeSiteDialog.12")), new GridBagConstraints(0, 1, 1, 1, 0., 0., GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 20, 0, 10), 0, 0)); //$NON-NLS-1$
		thisDataPanel.add(new JLabel(Messages.getString("MakeSiteDialog.13")), new GridBagConstraints(0, 2, 1, 1, 0., 0., GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 20, 0, 10), 0, 0)); //$NON-NLS-1$
		thisDataPanel.add(new JLabel(Messages.getString("MakeSiteDialog.14")), new GridBagConstraints(0, 3, 1, 1, 0., 0., GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 20, 0, 10), 0, 0)); //$NON-NLS-1$
		thisDataPanel.add(new JLabel(Messages.getString("MakeSiteDialog.15")), new GridBagConstraints(0, 4, 1, 1, 0., 0., GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 20, 0, 10), 0, 0)); //$NON-NLS-1$
		thisDataPanel.add(new JLabel(Messages.getString("MakeSiteDialog.16")), new GridBagConstraints(0, 5, 1, 1, 0., 0., GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 20, 0, 10), 0, 0)); //$NON-NLS-1$

		thisDataPanel.add(theTitleTextField, new GridBagConstraints(1, 0, 2, 1, 1., 0., GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 20), 0, 0));
		thisDataPanel.add(theXMLFileTextField, new GridBagConstraints(1, 1, 2, 1, 1., 0., GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 20), 0, 0));
		thisDataPanel.add(theHTMLFileTextField, new GridBagConstraints(1, 2, 2, 1, 1., 0., GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 20), 0, 0));
		thisDataPanel.add(theSiteLabel, new GridBagConstraints(1, 3, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));
		thisDataPanel.add(theRepositoryLabel, new GridBagConstraints(1, 4, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));
		thisDataPanel.add(theImageRepositoryLabel, new GridBagConstraints(1, 5, 1, 1, 0., 0., GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 10, 0, 10), 0, 0));

		thisDataPanel.add(thisModeButton, new GridBagConstraints(2, 3, 1, 1, 10., 0., GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 0, 20), 0, 0));
		thisDataPanel.add(thisBrowseRepositoryButton, new GridBagConstraints(2, 4, 1, 1, 10., 0., GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 0, 20), 0, 0));
		thisDataPanel.add(thisBrowseImageRepositoryButton, new GridBagConstraints(2, 5, 1, 1, 10., 0., GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(0, 10, 0, 20), 0, 0));

		JPanel thisProgressPanel = new JPanel();
		thisProgressPanel.setLayout(new BoxLayout(thisProgressPanel, BoxLayout.Y_AXIS));
		thisProgressPanel.setLayout(new GridBagLayout());
		thisProgressPanel.add(theProgressLabel, new GridBagConstraints(0, 0, 1, 1, 0., 0., GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(10, 20, 0, 20), 0, 0));
		thisProgressPanel.add(theProgressBar, new GridBagConstraints(0, 1, 1, 1, 1., 0., GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 20, 10, 20), 0, 0));

		JPanel thisCommandPanel = new JPanel();
		thisCommandPanel.add(theRunCheckBox);
		thisCommandPanel.add(thisCancelButton);
		thisCommandPanel.add(thisTransferButton);

		// events
		thisBrowseRepositoryButton.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				String thisPath = FileDialogs.getFolder(theProperties.getProperty("base", ".")); //$NON-NLS-1$ //$NON-NLS-2$
				if (thisPath != null && !thisPath.isEmpty())
				{
					theProperties.setProperty("repository", thisPath); //$NON-NLS-1$
					theRepositoryLabel.setText(thisPath);
				}
				else
				{
					theProperties.remove("repository"); //$NON-NLS-1$
					theRepositoryLabel.setText("<internal>"); //$NON-NLS-1$
				}
			}
		});

		thisBrowseImageRepositoryButton.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				String thisPath = FileDialogs.getFolder(theProperties.getProperty("base", ".")); //$NON-NLS-1$ //$NON-NLS-2$
				if (thisPath != null)
				{
					theProperties.setProperty("images", thisPath); //$NON-NLS-1$
					theImageRepositoryLabel.setText(thisPath);
				}
			}
		});

		thisModeButton.addActionListener(new java.awt.event.ActionListener()
		{
			public void actionPerformed(ActionEvent e)
			{
				XSiteDialog thisDialog = new XSiteDialog(theProperties);
				thisDialog.setModal(true);
				thisDialog.setVisible(true);
				theSiteLabel.setText(getSiteUrlString());
			}
		});

		thisTransferButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent e)
			{
				SwingUtilities.invokeLater(new Runnable()
				{
					@Override
					public void run()
					{
						transfer();
					}
				});
			}
		});

		thisCancelButton.addActionListener(new ActionListener()
		{
			public void actionPerformed(java.awt.event.ActionEvent e)
			{
				setVisible(false);
			}
		});

		theTitleTextField.getDocument().addDocumentListener(new DocumentListener()
		{
			public void removeUpdate(DocumentEvent e)
			{
				String thisTitle = theTitleTextField.getText();
				theHTMLFileTextField.setText(thisTitle + ".html"); //$NON-NLS-1$
				theXMLFileTextField.setText(thisTitle + ".xml"); //$NON-NLS-1$
			}

			public void insertUpdate(DocumentEvent e)
			{
				String thisTitle = theTitleTextField.getText();
				theHTMLFileTextField.setText(thisTitle + ".html"); //$NON-NLS-1$
				theXMLFileTextField.setText(thisTitle + ".xml"); //$NON-NLS-1$
			}

			public void changedUpdate(DocumentEvent e)
			{
			}
		});

		// assemble
		JPanel thisPanel = new JPanel();
		thisPanel.setLayout(new BoxLayout(thisPanel, BoxLayout.Y_AXIS));
		thisPanel.add(Box.createRigidArea(new Dimension(0, 10)));
		thisPanel.add(thisImageLabel);
		thisPanel.add(Box.createRigidArea(new Dimension(0, 10)));
		thisPanel.add(thisDataPanel);
		thisPanel.add(Box.createRigidArea(new Dimension(0, 10)));
		thisPanel.add(thisProgressPanel);
		thisPanel.add(thisCommandPanel);
		thisPanel.add(Box.createRigidArea(new Dimension(0, 10)));

		setContentPane(thisPanel);
	}

	/**
	 * Set document
	 * 
	 * @param thisDocument
	 *        document
	 */
	public void setDocument(Document thisDocument)
	{
		theDocument = thisDocument;
	}

	// H E L P E R S

	/**
	 * Get destination Url
	 * 
	 * @return site url string
	 */
	private String getSiteUrlString()
	{
		String thisMode = theProperties.getProperty("mode"); //$NON-NLS-1$
		if ("NET".equals(thisMode)) //$NON-NLS-1$
		{
			// ftp-specific check
			String thisServer = theProperties.getProperty("server", ""); //$NON-NLS-1$ //$NON-NLS-2$
			String thisDirectory = theProperties.getProperty("directory", ""); //$NON-NLS-1$ //$NON-NLS-2$
			String thisLogin = theProperties.getProperty("login", ""); //$NON-NLS-1$ //$NON-NLS-2$
			String thisPassword = theProperties.getProperty("password", ""); //$NON-NLS-1$ //$NON-NLS-2$
			if (!thisServer.isEmpty())
			{
				StringBuffer thisUrlBuffer = new StringBuffer();
				thisUrlBuffer.append("ftp://"); //$NON-NLS-1$
				thisUrlBuffer.append(thisLogin);
				thisUrlBuffer.append(":"); //$NON-NLS-1$
				thisUrlBuffer.append(thisPassword);
				thisUrlBuffer.append("@"); //$NON-NLS-1$
				thisUrlBuffer.append(thisServer);
				thisUrlBuffer.append("/"); //$NON-NLS-1$
				if (thisDirectory != null && !thisDirectory.isEmpty())
				{
					thisUrlBuffer.append(thisDirectory);
					thisUrlBuffer.append("/"); //$NON-NLS-1$
				}
				thisUrlBuffer.append(";type=i"); //$NON-NLS-1$
				return thisUrlBuffer.toString();
			}
		}
		else
		{
			// file system-specific check
			String thisPath = theProperties.getProperty("path", ""); //$NON-NLS-1$ //$NON-NLS-2$
			if (thisPath != null)
			{
				File thisDirectory = new File(thisPath);
				try
				{
					return thisDirectory.toURI().toURL().toString();
				}
				catch (MalformedURLException thisException)
				{
				}
			}
		}
		return ""; //$NON-NLS-1$
	}

	// T R A N S F E R

	/**
	 * Transfer
	 */
	private void transfer()
	{
		System.err.println("FTP transfer"); //$NON-NLS-1$
		boolean hasFailed = false;
		try
		{
			// repository check
			String thisRepository = theProperties.getProperty("repository"); //$NON-NLS-1$
			if (thisRepository != null && !thisRepository.isEmpty())
			{
				File thisRepositoryFolder = null;
				if (thisRepository.startsWith("file:")) //$NON-NLS-1$
					thisRepositoryFolder = new File(new URI(thisRepository));
				else
					thisRepositoryFolder = new File(thisRepository);
				if (!thisRepositoryFolder.exists() || !thisRepositoryFolder.isDirectory())
				{
					inform(Messages.getString("MakeSiteDialog.30") + thisRepository + Messages.getString("MakeSiteDialog.31")); //$NON-NLS-1$ //$NON-NLS-2$
					thisRepository = null;
				}
				else
					thisRepository = thisRepositoryFolder.toURI().toURL().toString();
			}
			if (thisRepository == null || thisRepository.isEmpty())
				thisRepository = SiteMaker.class.getResource("repository/").toURI().toURL().toString(); //$NON-NLS-1$

			// image repository check
			String thisImageRepository = theProperties.getProperty("images"); //$NON-NLS-1$
			if (thisImageRepository != null && !thisImageRepository.isEmpty())
			{
				File thisImageRepositoryFolder = null;
				if (thisImageRepository.startsWith("file:")) //$NON-NLS-1$
					thisImageRepositoryFolder = new File(new URI(thisImageRepository));
				else
					thisImageRepositoryFolder = new File(thisImageRepository);
				if (!thisImageRepositoryFolder.exists() || !thisImageRepositoryFolder.isDirectory())
				{
					inform(Messages.getString("MakeSiteDialog.30") + thisImageRepository + Messages.getString("MakeSiteDialog.31")); //$NON-NLS-1$ //$NON-NLS-2$
					thisImageRepository = null;
				}
				else
					thisImageRepository = thisImageRepositoryFolder.toURI().toURL().toString();
			}
			if (thisImageRepository == null || thisImageRepository.isEmpty())
			{
				thisImageRepository = new File(System.getProperty("user.home") + "/images").toURI().toURL().toString(); //$NON-NLS-1$ //$NON-NLS-2$
				inform(Messages.getString("MakeSiteDialog.32") + thisImageRepository + Messages.getString("MakeSiteDialog.33") + thisImageRepository); //$NON-NLS-1$ //$NON-NLS-2$
			}

			// data check
			String thisHTMLFile = theHTMLFileTextField.getText();
			String thisXMLFile = theXMLFileTextField.getText();
			String thisTitle = theTitleTextField.getText();
			if (thisHTMLFile.isEmpty() || thisXMLFile.isEmpty())
				return;

			// create site maker
			SiteMaker thisSiteMaker = null;
			String thisMode = theProperties.getProperty("mode"); //$NON-NLS-1$
			if ("NET".equals(thisMode)) //$NON-NLS-1$
			{
				// ftp-specific check
				String thisServer = theProperties.getProperty("server"); //$NON-NLS-1$
				String thisDirectory = theProperties.getProperty("directory"); //$NON-NLS-1$
				String thisLogin = theProperties.getProperty("login"); //$NON-NLS-1$
				String thisPassword = theProperties.getProperty("password"); //$NON-NLS-1$
				if (thisServer.isEmpty() || thisLogin.isEmpty())
					return;

				// create
				thisSiteMaker = new FtpSiteMaker(theDocument, thisRepository, thisImageRepository, thisHTMLFile, thisXMLFile, thisTitle, thisServer, thisDirectory, thisLogin, thisPassword);
			}
			else
			{
				// file system-specific check
				String thisPath = theProperties.getProperty("path"); //$NON-NLS-1$
				if (thisPath != null)
				{
					File thisFolder = new File(thisPath);
					if (!thisFolder.exists())
					{
						inform(Messages.getString("MakeSiteDialog.40") + thisPath + Messages.getString("MakeSiteDialog.41")); //$NON-NLS-1$ //$NON-NLS-2$
						if (!thisFolder.mkdirs())
						{
							inform(Messages.getString("MakeSiteDialog.40") + thisPath + Messages.getString("MakeSiteDialog.42")); //$NON-NLS-1$ //$NON-NLS-2$
							return;
						}
					}
				}

				// create
				thisSiteMaker = new FileSiteMaker(theDocument, thisRepository, thisImageRepository, thisPath, thisHTMLFile, thisXMLFile, theTitleTextField.getText());
			}

			if (thisSiteMaker != null)
			{
				// add observers
				thisSiteMaker.addObserver(new Observer()
				{
					@SuppressWarnings("unchecked")//$NON-NLS-1$
					public void update(Observable thisO, Object thisArg)
					{
						Pair<String, Integer> thisInfo = (Pair<String, Integer>) thisArg;
						theProgressLabel.setText(thisInfo.theFirst);
						theProgressBar.setValue(thisInfo.theSecond);
					}
				});

				// make site
				boolean hasSucceeded = thisSiteMaker.make();

				// delete observers
				thisSiteMaker.deleteObservers();

				// result
				if (!hasSucceeded)
				{
					hasFailed = true;
					return;
				}
			}
		}
		catch (MalformedURLException thisException)
		{
			System.err.println(Messages.getString("MakeSiteDialog.50") + thisException.toString()); //$NON-NLS-1$
			return;
		}
		catch (URISyntaxException thisException)
		{
			System.err.println("Transfer: " + thisException.toString()); //$NON-NLS-1$
			return;
		}
		catch (IOException thisException)
		{
			System.err.println("Transfer: " + thisException.toString()); //$NON-NLS-1$
			return;
		}

		// chain to run
		if (!hasFailed & theRunCheckBox.isSelected())
		{
			// update data from properties
			theProperties.setProperty("page", theHTMLFileTextField.getText()); //$NON-NLS-1$
			RunSiteDialog thisDialog = new RunSiteDialog(theProperties);
			thisDialog.setModal(true);
			thisDialog.setVisible(true);
		}

		setVisible(false);
	}

	// I N F O R M

	/**
	 * Inform dialog
	 * 
	 * @param thisMessage
	 *        message
	 */
	protected void inform(String thisMessage)
	{
		String[] theseLines = thisMessage.split("\n"); //$NON-NLS-1$
		JOptionPane.showMessageDialog(null, theseLines, Messages.getString("MakeSiteDialog.60"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$
	}

	/*
	 * (non-Javadoc)
	 * @see java.awt.Dialog#setVisible(boolean)
	 */
	public void setVisible(boolean thisFlag)
	{
		if (thisFlag)
		{
			// read properties into components
			theSiteLabel.setText(getSiteUrlString());
			theRepositoryLabel.setText(theProperties.getProperty("repository", "<internal>")); //$NON-NLS-1$ //$NON-NLS-2$
			theImageRepositoryLabel.setText(theProperties.getProperty("images")); //$NON-NLS-1$
			theProgressLabel.setText(Messages.getString("MakeSiteDialog.20")); //$NON-NLS-1$
			theProgressBar.setValue(0);

			pack();
			Utils.center(this);
		}
		else
		{
			// update properties from components
			theProperties.setProperty("page", theHTMLFileTextField.getText()); //$NON-NLS-1$
		}
		super.setVisible(thisFlag);
	}

	/**
	 * Main
	 * 
	 * @param theseArgs
	 *        arguments
	 * @throws MalformedURLException
	 */
	static public void main(String[] theseArgs) throws MalformedURLException
	{
		UIManager.put("swing.boldMetal", false); //$NON-NLS-1$
		Properties theseSettings = Persist.getSettings("jFamilyTree-generator"); //$NON-NLS-1$
		String thisStringUrl = null;
		if (theseArgs.length >= 1)
			thisStringUrl = theseArgs[0];
		else
		{
			JOptionPane.showMessageDialog(null, new String[] { Messages.getString("MakeSiteDialog.70") }, Messages.getString("MakeSiteDialog.71"), JOptionPane.WARNING_MESSAGE); //$NON-NLS-1$ //$NON-NLS-2$
			thisStringUrl = FileDialogs.getXmlUrl(theseSettings.getProperty("base", ".")); //$NON-NLS-1$ //$NON-NLS-2$
		}
		if (thisStringUrl == null)
			System.exit(0);
		Document thisDocument = new Parser().makeDocument(new URL(thisStringUrl), null);
		if (thisDocument == null)
			System.exit(0);
		MakeSiteDialog thisDialog = new MakeSiteDialog(theseSettings);
		thisDialog.setDocument(thisDocument);
		thisDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
		thisDialog.setModal(true);
		thisDialog.setVisible(true);
		Persist.saveSettings("jFamilyTree-generator", theseSettings); //$NON-NLS-1$
		System.exit(0);
	}
}
